import * as CONSTANT from "@/store/constant.js";

const defaultState = []
const commentReducer = (state = defaultState, action) => {
    let comment;
    let comments;
    let commentId;
    let filerConmments;
    switch (action.type) {
        case CONSTANT.COMMENT_CREATE_RESULT:
            comment = action.payload;
            return [comment, ...state];
        case CONSTANT.COMMENT_GET_RESULT:
            comments = action.payload;
            return comments;
        case CONSTANT.COMMENT_DELETE_RESULT:
            console.log(1)
            commentId = action.payload;
            filerConmments =  state.filter(item => item.id !== commentId);
            return filerConmments;
        default:
            return state;
    }
}
export default commentReducer;